package com.it;

public class StringBuilderDemo {
    public static void main(String[] args) {
        /**
         * 构造一个字符串生成器没有字符和一个初始容量16字符。
         */
        StringBuilder stringBuilder = new StringBuilder();

        /**
         * append(String str)
         * 将指定的字符串附加到这个字符序列。
         */
        StringBuilder append = stringBuilder.append("hello world");
        System.out.println("append = " + append);

        /**
         * replace(int start, int end, String str)
         * 替换的子字符串中的字符与字符序列 String指定。
         * [int start, int end)
         */
        StringBuilder pp = append.replace(2, 4, "pp");
        System.out.println("oo = " + pp);

        /**
         * delete(int start, int end)
         * 删除这个序列的子字符串中的字符。
         * [int start, int end]
         */
        StringBuilder delete = pp.delete(1, 3);
        System.out.println("delete = " + delete);


        /**
         * insert(int offset, String str)
         * 将字符串插入这个字符序列。
         */
        StringBuilder stringBuilder2 = new StringBuilder("hello");
        StringBuilder insert = stringBuilder2.insert(4, "-world");
        System.out.println("insert = " + insert);


        /**
         * reverse()
         * 导致这个字符序列,取而代之的是序列的反向。
         */
        StringBuilder stringBuilder1 = new StringBuilder("helloworld");
        StringBuilder reverse = stringBuilder1.reverse();
        System.out.println("reverse = " + reverse);


    }
}
